﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Text;
using System.Data.SqlClient;
using System.Collections.ObjectModel;
using MvcApplication6.DAL.Helper;
using MvcApplication6.Models;

namespace MvcApplication6.DAL
{
    public class Category_eventDAL
    {
        //---------------------Category_eventSearch-----------------------------
        public List<Category_eventModel> Category_eventSearch()
        {

            List<Category_eventModel> lst = new List<Category_eventModel>();

            Category_eventModel obj = null;

            SqlDataReader dr = SQLHelper.ExecuteReader("[spCategory_eventSearch]");
            while (dr.Read())
            {
                obj = new Category_eventModel();

                obj.Id = int.Parse(dr["id"].ToString());
                obj.Name = dr["name"].ToString();
                obj.Content_template = dr["content_template"].ToString();

                lst.Add(obj);
            }
            dr.Close();
            return lst;
        }

        //---------------------Category_eventSearchById-----------------------------
        public Category_eventModel Category_eventSearchById(int id)
        {
            Category_eventModel obj = null;

            Collection<SqlParameter> parameterList = new Collection<SqlParameter>();

            parameterList.Add(new SqlParameter("@id", id));


            SqlDataReader dr = SQLHelper.ExecuteReader("spCategory_eventSearchById", parameterList);
            while (dr.Read())
            {
                obj = new Category_eventModel();

                obj.Id = int.Parse(dr["id"].ToString());
                obj.Name = dr["name"].ToString();
                obj.Content_template = dr["content_template"].ToString();

            }
            dr.Close();
            return obj;
        }

        //---------------------Category_eventInsert-----------------------------
        public int Category_eventInsert(string name, string content_template)
        {
            Collection<SqlParameter> parameterList = new Collection<SqlParameter>();

            parameterList.Add(new SqlParameter("@name", name));
            parameterList.Add(new SqlParameter("@content_template", content_template));

            int i = SQLHelper.ExecuteNonQuery("spCategory_eventInsert", parameterList);

            return i;
        }

        //---------------------Category_eventUpdate-----------------------------
        public int Category_eventUpdate(int id, string name, string content_template)
        {
            Collection<SqlParameter> parameterList = new Collection<SqlParameter>();

            parameterList.Add(new SqlParameter("@id", id));
            parameterList.Add(new SqlParameter("@name", name));
            parameterList.Add(new SqlParameter("@content_template", content_template));

            int i = SQLHelper.ExecuteNonQuery("spCategory_eventUpdate", parameterList);

            return i;
        }

        //---------------------Category_eventDelete-----------------------------
        public int Category_eventDelete(int id)
        {
            Collection<SqlParameter> parameterList = new Collection<SqlParameter>();

            parameterList.Add(new SqlParameter("@id", id));

            int i = SQLHelper.ExecuteNonQuery("spCategory_eventDelete", parameterList);

            return i;
        }
    }
}